package com.schoolai.schoolset.auth.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.plugin.auth.api.Resource;
import com.schoolai.util.base.Result;
import com.schoolai.util.enums.ResultEnum;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import java.io.IOException;
import java.util.HashMap;

/**
 * Copyright(C),2019-2025，XX公司
 * FileName:MyAuthenticationEntryPoint
 * Author:bobby
 * 创建时间：2025/10/23 11:40
 * Description:实现AuthenticationEntryPoint接口
 * History:
 * <auth>        <time>       <version>       <desc>
 * 作者          修改时间       版本号         描述
 */

public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {

        //获取错误信息
        //String localizedMessage = authException.getLocalizedMessage();



        //返回响应
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(JSON.toJSONString(Result.build(ResultEnum.TOKEN_ERROR)));
    }
}
